package com.example.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditRateActivity extends Activity {

    private TextView currencyName;
    private EditText newExchangeRate;
    private Button confirmButton;
    private String currency;
    private String originalRate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_rate);

        // 获取传递过来的货币和汇率信息
        currencyName = findViewById(R.id.currencyName);
        newExchangeRate = findViewById(R.id.newExchangeRate);
        confirmButton = findViewById(R.id.confirmButton);

        Intent intent = getIntent();
        currency = intent.getStringExtra("currency");
        originalRate = intent.getStringExtra("rate");

        // 设置货币名称和原汇率
        currencyName.setText(currency);
        newExchangeRate.setText(originalRate);

        // 确认按钮点击事件
        confirmButton.setOnClickListener(v -> {
            String updatedRate = newExchangeRate.getText().toString();

            // 将修改后的数据和货币名称一起返回
            Intent resultIntent = new Intent();
            resultIntent.putExtra("currency", currency); // 传递货币名称
            resultIntent.putExtra("updatedRate", updatedRate); // 传递更新后的汇率
            setResult(RESULT_OK, resultIntent);
            finish();
        });
    }
}
